<script setup lang="ts" name="DictDataDetail">
import { LIST_CLASS_COLUMN, LIST_CLASS_ENUM } from "@/views/system/dict/const";
import { getDictDataApi } from "@/api/system/dictData";

const { sys_normal_disable } = useDict("sys_normal_disable");

const emit = defineEmits(['closeDialog']);

const props = defineProps({
  id: {
    default: null,
  },
  title: {
    type: String,
    default: false,
  }
});

const open = ref(false);

const form = ref<DictDataRecord>({});

/** 获取字典值管理详情 */
function getData() {
  if (isEmpty(props.id)) {
    open.value = true;
  } else {
    getDictDataApi(props.id).then(response => {
      form.value = response.data;
      open.value = true;
    }).catch(err => {
      closeDialog(false);
    })
  }
}

/** 关闭弹窗 */
function closeDialog(refresh: boolean) {
  open.value = false;
  emit("closeDialog", refresh);
}

watch(open, (val) => {
  if (!val) {
    closeDialog(false);
  }
});

getData();
</script>

<template>
  <!-- 字典值管理详情对话框 -->
  <el-dialog :title="title" v-model="open" width="700px" append-to-body>
    <div class="detail-form">
      <el-form ref="dictDataForm" :model="form" label-width="80px">
        <el-form-item label="字典编号" prop="dictCode">
          {{ form.dictCode }}
        </el-form-item>
        <el-form-item label="字典类型" prop="dictType">
          {{ form.dictType }}
        </el-form-item>
        <el-form-item label="数据标签" prop="dictLabel">
          <span v-if="form.listClass == '' || form.listClass == LIST_CLASS_ENUM.default">
            {{ form.dictLabel }}
          </span>
          <el-tag v-else :type="form.listClass">
            {{ form.dictLabel }}
          </el-tag>
        </el-form-item>
        <el-form-item label="数据键值" prop="dictValue">
          {{ form.dictValue }}
        </el-form-item>
        <el-form-item label="样式属性" prop="cssClass">
          {{ form.cssClass }}
        </el-form-item>
        <el-form-item label="显示排序" prop="dictSort">
          {{ form.dictSort }}
        </el-form-item>
        <el-form-item label="回显样式" prop="listClass">
          <span v-if="form.listClass == '' || form.listClass == LIST_CLASS_ENUM.default">
             <dict-tag :options="LIST_CLASS_COLUMN" :value="form.listClass" />
          </span>
          <el-tag v-else :type="form.listClass">
            <dict-tag :options="LIST_CLASS_COLUMN" :value="form.listClass" />
          </el-tag>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <dict-tag :options="sys_normal_disable" :value="form.status" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          {{ form.createTime }}
        </el-form-item>
        <el-form-item label="备注" prop="remark" class="item-describe">
          {{ form.remark }}
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="closeDialog(false)">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>

</style>